package com.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.pojo.Todo;
import com.example.service.TodoService;

@RestController
public class TodoController {

	@Autowired
	private TodoService todoService;

	@RequestMapping(value = "/get.json", method = RequestMethod.GET)
	public Todo get(@RequestParam(value = "id") String id) {
		return todoService.select(Integer.parseInt(id));
	}

	@RequestMapping(value = "/set.json", method = RequestMethod.GET)
	public Todo set(@RequestParam(value = "title") String title, @RequestParam(value = "details") String details) {
		int id = todoService.insert(title, details);
		return todoService.select(id);	
	}
	
	@RequestMapping(value = "/set1.json", method = RequestMethod.GET)
	public Todo set1(@RequestParam(value = "title") String title, @RequestParam(value = "details") String details) {
		int id = todoService.insert1(title, details);
		return todoService.select1(id);	
	}
	
	@RequestMapping(value = "/set2.json", method = RequestMethod.GET)
	public Todo set2(@RequestParam(value = "title") String title, @RequestParam(value = "details") String details) {
		int id = todoService.insert2(title, details);
		return todoService.select2(id);	
	}

}